package mspbots.liongard.common;

import io.swagger.annotations.ApiModel;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.UUID;

/**
 * mspbots.data.autotask.utils.ResultResponse
 *
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 * @date Created by 2020/7/22
 */
@Data
@NoArgsConstructor
@ApiModel("Request api result entity model")
public class ResultSync implements Serializable {

    private Long tenantId;

    @NotEmpty
    private UUID requestId;

    @NotEmpty
    private QueryParams params;

    @NotEmpty
    private LocalDateTime time;

    @NotEmpty
    private long elapsedTime;

    @NotEmpty
    private int count;

    @NotEmpty
    private HttpStatus status;

    @NotEmpty
    private String action;

    @NotEmpty
    private Object msg;

    @Builder
    public ResultSync(long elapsedTime, HttpStatus status, String action, Object msg) {
        this.elapsedTime = elapsedTime;
        this.msg = msg;
        this.status = status;
        this.action = action;
        this.requestId = UUID.randomUUID();
        this.time = LocalDateTime.now();
    }

    /**
     * @return default ResultSync body
     */
    public static ResultSync withDefault(String action) {
        return new ResultSync(System.currentTimeMillis(), HttpStatus.OK, action, "This request api success.");
    }

    public ResultSync setParams(QueryParams params) {
        this.params = params;
        return this;
    }
}
